package com.cms.certificate.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.cms.common.annotation.Log;
import com.cms.common.core.controller.BaseController;
import com.cms.common.core.domain.AjaxResult;
import com.cms.common.enums.BusinessType;
import com.cms.certificate.domain.CmsCertificate;
import com.cms.certificate.service.ICmsCertificateService;
import com.cms.common.utils.poi.ExcelUtil;
import com.cms.common.core.page.TableDataInfo;

/**
 * 证书文件Controller
 * 
 * @author rjxy
 * @date 2025-09-29
 */
@RestController
@RequestMapping("/certificate/certificate")
public class CmsCertificateController extends BaseController
{
    @Autowired
    private ICmsCertificateService cmsCertificateService;

    /**
     * 查询证书文件列表
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:list')")
    @GetMapping("/list")
    public TableDataInfo list(CmsCertificate cmsCertificate)
    {
        startPage();
        List<CmsCertificate> list = cmsCertificateService.selectCmsCertificateList(cmsCertificate);
        return getDataTable(list);
    }

    /**
     * 导出证书文件列表
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:export')")
    @Log(title = "证书文件", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CmsCertificate cmsCertificate)
    {
        List<CmsCertificate> list = cmsCertificateService.selectCmsCertificateList(cmsCertificate);
        ExcelUtil<CmsCertificate> util = new ExcelUtil<CmsCertificate>(CmsCertificate.class);
        util.exportExcel(response, list, "证书文件数据");
    }

    /**
     * 获取证书文件详细信息
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(cmsCertificateService.selectCmsCertificateById(id));
    }

    /**
     * 新增证书文件
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:add')")
    @Log(title = "证书文件", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CmsCertificate cmsCertificate)
    {
        return toAjax(cmsCertificateService.insertCmsCertificate(cmsCertificate));
    }

    /**
     * 修改证书文件
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:edit')")
    @Log(title = "证书文件", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CmsCertificate cmsCertificate)
    {
        return toAjax(cmsCertificateService.updateCmsCertificate(cmsCertificate));
    }

    /**
     * 删除证书文件
     */
    @PreAuthorize("@ss.hasPermi('certificate:certificate:remove')")
    @Log(title = "证书文件", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(cmsCertificateService.deleteCmsCertificateByIds(ids));
    }
}
